package com.sky.common.task;

import com.sky.business.sys.service.MQTTMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * mqtt消息定时清理
 */
@Component
public class MqttMessageCleanTask {

    @Autowired
    private MQTTMessageService mqttMessageService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void doTask() {
        LocalDateTime expireDateTime = LocalDateTime.now().plusMonths(-1);
        mqttMessageService.deleteByCreateDateBefore(expireDateTime);
    }
}
